<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="jakarta.servlet.http.Cookie" %>
<html>
<head>
    <title>留言网站</title>
    <link rel="stylesheet" href="table.css">
    <%
        Cookie cookie[] = request.getCookies();
        if (cookie != null) {
            String uname = null;
            String uid = null;
            for (int i = 0; i < cookie.length; i++) {
                if (cookie[i].getName().equals("uname")) {
                    uname = cookie[i].getValue();
                }
                if (cookie[i].getName().equals("uid")) {
                    uid = cookie[i].getValue();
                }
            }
            if (uname != null && uid != null) {
                if (!uname.equals("") && !uid.equals("")) {
                    out.println("<script>alert('登录状态存在，正在前往留言界面')</script>");
                    response.setHeader("refresh", "0;URL=message.jsp");
                }
            }
        }
    %>
</head>
<body>
<h1>欢迎来到我的留言网站</h1>
<form action="check.jsp" method="post">
    <table>
        <tbody>
        <tr>
            <td>账号：</td>
            <td><input type="text" name="id"/></td>
        </tr>
        <tr>
            <td>密码：</td>
            <td><input type="password" name="upwd"/></td>
        </tr>
        <tr>
            <td>账户类型:</td>
            <td><select name="identity">
                <option value="user">用户</option>
                <option value="manager">管理员</option>
            </select>
            </td>
        </tr>
        <tr>
            <td><input type="submit" value="登录" name="use_type"></td>
            <td><input type="submit" value="注册" name="use_type"></td>
        </tr>
        </tbody>
    </table>
</form>
</body>
</html>